'use strict';
import React, {Component} from 'react';
import {
    TouchableOpacity,
    View,
    Text,
    Image,
    Dimensions,
    StyleSheet,
    NativeModules,
    Linking,
    Platform,
} from 'react-native';
import ReviewsPage from "../Pages/ReviewsPage";
import Global from "../Commom/GlobalConst";
import Toast from "../Utils/toast";
let width = Dimensions.get("window").width;
import RegisteredContainer from '../Containers/RegisteredContainer';
const styles = StyleSheet.create({
    content: {
        backgroundColor: 'white',
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center',
        height: 45,
    },
    imageBox: {
        width: 15,
        height: 15,
        resizeMode: 'contain',
        marginRight: 8,
    },
    textBox: {
        fontSize: 13,
        color: '#666'
    }
});

class BottomCommentBtn extends Component {

    callPhone() {
        let phone = this.props.phone;
        if (Platform.OS === 'android') {
            NativeModules.MakePhoneCallModule.makePhoneCall(phone);
        } else if (Platform.OS === 'ios') {
            Linking.openURL('tel:' + phone).catch(err => console.log('打开电话失败:', err));
        }
    }

    ReviewsPage(rid, type) {
        if (Global.Const.token == '') {
            // Toast.show('请先登录！');
            this.props.navigator.push({
                id: 'RegisteredContainer',
                component: RegisteredContainer,
                passProps: {},
            });
            return;
        }
        this.props.navigator.push({
            name: 'ReviewsPage',
            component: ReviewsPage,
            passProps: {
                rid: rid,
                type: type,
                refreshComments: ()=>this.props.refreshComments(),
            },
        })
    }

    render() {
        let {rid, type}=this.props;
        return (
            <View style={[styles.content, {
                width,
                borderTopWidth: 1,
                borderTopColor: "#F2F3F5"
            }]}>
                <TouchableOpacity
                    onPress={() => this.callPhone()}
                    style={[styles.content, {
                        flex: 1,
                        borderRightWidth: 1,
                        borderRightColor: '#F2F3F5',
                    }]}
                >
                    <View style={styles.content}>
                        <Image style={styles.imageBox}
                               source={require('../../Image/icon_gray_booking.png')}/>
                        <Text style={styles.textBox}>预定</Text>
                    </View>
                </TouchableOpacity>
                <TouchableOpacity
                    onPress={() => this.ReviewsPage(rid,type)}
                    style={[styles.content, {flex: 1,}]}
                >
                    <View style={styles.content}>
                        <Image style={styles.imageBox}
                               source={require('../../Image/icon_comment.png')}/>
                        <Text style={[styles.textBox,{color: "#38D68B"}]}>点评</Text>
                    </View>
                </TouchableOpacity>
            </View>
        )
    }

}

export default BottomCommentBtn;